package shawn.projection;

import java.io.Serializable;
import java.text.DecimalFormat;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Point;

/**
 * 经纬度坐标点
 * @author zhangzuoqiang
 * @date 2015年8月20日 上午9:57:49
 */
public class LngLatPoint implements Serializable {

  private static final long serialVersionUID = -6920465367164121302L;

  public double lng;
  public double lat;

  public LngLatPoint() {
    this.lng = 0;
    this.lat = 0;
  }

  public LngLatPoint(double lng, double lat) {
    this.lng = lng;
    this.lat = lat;
  }

  public LngLatPoint(Coordinate c) {
    this.lng = c.x;
    this.lat = c.y;
  }

  public LngLatPoint(Point p) {
    this.lng = p.getX();
    this.lat = p.getY();
  }

  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (!(o instanceof LngLatPoint)) {
      return false;
    }
    final LngLatPoint t = (LngLatPoint) o;
    if (lng == t.lng && lat == t.lat) {
      return true;
    } else {
      return false;
    }
  }

  public Coordinate toCoordinate() {
    return new Coordinate(lng, lat);
  }

  public String toString() {
    DecimalFormat df = new DecimalFormat("0.000000");
    return df.format(lng) + "," + df.format(lat);
  }
}
